package kursynbp;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class XmlDomReader implements XmlReader {

	@Override
	public Document getXmlDocument(URL url) {
		
		try {
	        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	        dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
	        DocumentBuilder db = dbf.newDocumentBuilder();
	        Document xmlDoc = db.parse(url.openStream());
	    	xmlDoc.getDocumentElement().normalize();
	
	    	return xmlDoc;
		} catch (Exception ex) {
			throw new XmlFetchingException();
		}
	}
}
